package com.ruoyi.web.controller.school;

import com.ruoyi.system.domain.SchoolUser;
import com.ruoyi.system.service.impl.SchoolServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/school")
public class SchoolController {

    @Autowired
   private SchoolServiceImpl schoolService;

    //添加
    @PostMapping("/add")
    public String add(@RequestBody SchoolUser schoolUser){

        if (schoolUser.getUserName() == null || schoolUser.getUserName().isEmpty()) {
            throw new IllegalArgumentException("UserName is required");
        }
        String add = schoolService.add(schoolUser);
        return add;
    }

    //删除
    @DeleteMapping("/delete/{id}")
    public String delete(@PathVariable("id") Integer id){

        String delete = schoolService.delete(id);
        return delete;
    }

    //修改
    @PostMapping("/update")
    public String update(@RequestBody SchoolUser schoolUser){

        String update = schoolService.update(schoolUser);
        return update;
    }

    //查询
    @PostMapping("/query/{id}")
    public List<SchoolUser> query(@PathVariable("id") Integer id){

        List<SchoolUser> query = schoolService.query(id);
        return query;

    }

}
